package org.novaacropole.util;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class EmailListener implements ServletContextListener {

	ScheduledExecutorService executorService;

	public void contextInitialized(ServletContextEvent arg0) {
		executorService = Executors.newScheduledThreadPool(1);
		executorService.scheduleWithFixedDelay(new SMTPClient(), 0, 1, TimeUnit.MINUTES);
		executorService.scheduleWithFixedDelay(new POPClient(), 0, 1, TimeUnit.MINUTES);
	}

	public void contextDestroyed(ServletContextEvent arg0) {
		executorService.shutdownNow();
	}

}
